from datetime import datetime, timedelta
import time

def get_date(days):
    c = datetime.today()
    b = c + timedelta(days=days)
    return print(datetime.strftime(b, "%Y-%m-%d %H:%M:%S"))

get_date(-3)


#time模块
#获取当前时间
time.localtime()
#改变时区
#import os
#os.environ['TZ'] ='US'
#time.tzset()

#时间戳
time.time()
#时间格式的转换
#time.struct_time->str
time.strftime("%Y-%m-%d %H:%M:%S")
#str->time.struct_time
time.strptime("1999-10-01 10:00:01", "%Y-%m-%d %H:%M:%S")
#time.struct_time->tuple
tuple(time.localtime())
#tuple->time.struct_time
time.struct_time(tuple(time.localtime()))
#time.struct_time->timestamp
time.mktime(time.localtime())
#timestamp->time.struct_time
time.localtime(time.time())#有时区
time.gmtime(time.time())   #没有时区

#时间的运算
#time.struct_time->tuple->new_tuple->time.struct_time
#时间休眠
time.sleep(3)


#datetime模块
#查看当前时间
datetime.now()
datetime.today()
datetime.utcnow()
#时间戳
datetime.now().timestamp()
#时间格式的转换
#datetime.datetime->str
c=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
#str->datetime.datetime
datetime.strptime(c, "%Y-%m-%d %H:%M:%S")
#datetime.datetime->tuple
e=tuple(datetime.now().timetuple())
#tuple->datetime.datetime
datetime(*datetime.now().timetuple()[:-3])
#datetime.datetime->timestamp
t=datetime.today().timestamp()
#timestamp->datetime.datetime
datetime.fromtimestamp(t)
#时间运算
l = datetime.today()
l+timedelta(days=1)
l+timedelta(hours=1)
l+timedelta(seconds=1)

